<?php

require_once(PATH_CLASS.'security.class.php');

/**
 * 
 */
class updateScore extends form {
  var $params = array();
  public function getDefaults() {
    $ret = parent::getDefaults();
    $ret = array_merge($ret,array(
       'class'      => array('none')
      ,'match_id'   => 0
      ,'match'      => null
      ,'equipe_A'   => ''
      ,'equipe_B'   => ''
      ,'titre_A'   => ''
      ,'titre_B'   => ''
    ));
    
    return $ret;
  }
  
  public function isAuthorized() {
    $ret = parent::isAuthorized();
    
    if($ret){
      $ret = security::canUpdateScore();
    }
    return $ret;
  }
  
  public function __construct($params) {
    
    //parent::__construct($params);
    $p = array_merge($this->getDefaults(),$params);
    
    if(!$this->isAuthorized()){
      throw new Exception("Non pas le droit");
    }
    
    if($p['match']==null){
      $match = match::getMatch($p['match_id']);
    }
    
    if($match){
      $p['match']     = $match;
      $p['equipe_A']  = '';
      $p['equipe_B']  = '';
      
      if($equipe = equipe::getEquipe($match->match_equipe_A)){
        $p['equipe_A'] = $equipe;
      }
      
      if($equipe = equipe::getEquipe($match->match_equipe_B)){
        $p['equipe_B'] = $equipe;
      }
        
    }
    
    $this->params = $p;
    
  }
  
  
  
}

